const { router, fs, urlencodedParser } = require("../CustomMethod");
const fetchVideoLinks = require("../CustomMethod/Video");

// 搜索
router.post("/video", urlencodedParser, (req, res) => {
  let keyword = req.body.type; // 注意这里应该是 type 而不是 keyword
  let url = "https://www.cbhfox.com/?";
  fetchVideoLinks(url, keyword, res);
});

// 简化路由处理函数
const handleRoute = (type, url) => {
  router.post(type, urlencodedParser, (req, res) => {
    fetchVideoLinks(url, "", res);
  });
};

// 电视剧
handleRoute("/tv", "https://www.cbhfox.com/cbhyy/dianshiju.html");

// 动漫
handleRoute("/anime", "https://www.cbhfox.com/cbhyy/dongmna.html");

// 综艺
handleRoute("/variety", "https://www.cbhfox.com/cbhyy/zongyi.html");

// 电影
handleRoute("/movie", "https://www.cbhfox.com/cbhyy/dianying.html");

module.exports = router;
